package com.qyhl.webtv.commonlib.item;

import android.content.Context;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import com.orhanobut.hawk.Hawk;
import com.qyhl.webtv.basiclib.utils.glide.GlideOptionsUtils;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.Map;

/**
 * Created by qyhl on 2017/11/15.
 * 列表广告大图类型
 */

public class ItemAdvLarge implements ItemViewDelegate<GlobalNewsBean> {
    private Context context;

    public ItemAdvLarge(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.news_item_newslist_advlarge;
    }

    @Override
    public boolean isForViewType(GlobalNewsBean item, int position) {
        if ("4".equals(item.getType()) && item.getNewsStyle() == 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void convert(ViewHolder holder, GlobalNewsBean bean, int position) {
        TextView title = holder.getView(R.id.title);
        title.setText(bean.getTitle());

        title.setTextColor(context.getResources().getColor(R.color.global_black_lv1));
        if (CommonUtils.getInstance().getHasHistory()) {
            if (Hawk.contains("readHistory")) {
                Map<String, String> historyMap = CommonUtils.getInstance().getReadHistory();
                for (Map.Entry<String, String> vo : historyMap.entrySet()) {
                    String newsId = (String) vo.getKey();
                    if (bean.getNewsId().equals(newsId)) {
                        title.setTextColor(context.getResources().getColor(R.color.global_gray_lv1));
                        break;
                    }
                }
            }
        }


        RoundedImageView cover = holder.getView(R.id.cover);
        Glide.with(context)
                .load(bean.getCover())
                .apply(GlideOptionsUtils.getInstance().getOptions(R.drawable.cover_large_default, R.drawable.cover_large_default))
                .into(cover);
    }
}
